function ShowHideDiv(id){
  try{
    var panel=document.getElementById(id);
    if(panel){
      if(panel.style.display=='none'){
        panel.style.display='block';
      }else{
        panel.style.display='none';
      }
    }
  }catch(e){}
}

function externallinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external nofollow")
			anchor.target = "_blank";
	}
}
window.onload = externallinks;

//关于注册页面的用户名判断
function CheckName(BlogPath){
	var TempStr, StrHtml, Bool;
	$("CheckName").innerHTML = "<font color=blue>检测用户名...</font>"
	var username = document.forms["frm"].username.value;
	var HoldValue = $("postback_username").value;
	if (strlen(username) < 3){
		$("postback_username").value = "False|$|" + HoldValue.split("|$|")[1] + HoldValue.split("|$|")[2];
		$("CheckName").innerHTML = "<font color=red>用户名少于三个字符！</font>";
	}else{
		var ajax = new AJAXRequest;
		ajax.get(
				 BlogPath + "index.php?m=ajax&do=checkname&username="+ escape(username),
				 function(obj) {
					 TempStr = obj.responseText;
					 StrHtml = TempStr.split("|$|")[0];
					 Bool = TempStr.split("|$|")[1];
					 if ( Bool == "True" ){
						 $("postback_username").value = "True|$|" + HoldValue.split("|$|")[1] + "|$|" + HoldValue.split("|$|")[2];
						 $("CheckName").innerHTML = "<font color=blue>" + StrHtml + "</font>";
					 }else{
						 $("postback_username").value = "False|$|" + HoldValue.split("|$|")[1] + "|$|" + HoldValue.split("|$|")[2];
						 $("CheckName").innerHTML = "<font color=red>" + StrHtml + "</font>";
					 }
				 }
		 );
	}
}

//判断中英文：
function isChinese(str)
{
     var lst = /[u00-uFF]/;
     return !lst.test(str);
}

function strlen(str) 
{
    var strlength=0;
    for (i=0;i<str.length;i++)
   {
      if (isChinese(str.charAt(i))==true)
         strlength=strlength + 2;
      else
         strlength=strlength + 1;
   }
return strlength;
}

//设置Cookie
function set_cookie(name, value) {
	var argv = set_cookie.arguments;
	var argl = set_cookie.arguments.length;
	var expire = argl > 2 ? argv[2] : null;
	if (expire == null) {
		var expire = new Date();
		expire.setTime(expire.getTime() + 365 * 24 * 3600);
	}
	document.cookie = name+'='+escape(value)+';path=/;expire='+expire.toGMTString();
}

//获取COOKIE
function get_cookie(name) {
	 if (document.cookie.length > 0) {
		 var start = name + '=';
		 var offset = document.cookie.indexOf(start);
		 if (offset != -1) {
			offset += start.length;
			var end = document.cookie.indexOf(';',offset);
			if (end == -1) {
				end = document.cookie.length;
			}
			return unescape(document.cookie.substring(offset, end));
		 }
	 }
	 return '';
}

//保存用户信息
function set_guestinfo() {
	if ($('#remember').attr('checked')) {
		set_cookie('username',$('#username').val());
		set_cookie('email',$('#email').val());
		set_cookie('homepage',$('#homepage').val());
		set_cookie('remember','1');
	} else {
		var expire = new Date();
		expire.setTime(expire.getTime() - 3600);
		set_cookie('username','',expire);
		set_cookie('email','',expire);
		set_cookie('homepage','',expire);
		set_cookie('remember','0',expire);	
	}
}
//可通过增加一个增加一个参数改变 id="post_comment_title" 的文字
function reply_comment(id) {
	if (arguments[1]) {
		$("#post_comment_title").text(arguments[1]);
	}
	$(":input[@name='rid']").val(id);
}
